package com.dongdongshop.Controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sellController")
public class SellerController {

    @Reference
    private SellerService sellerService;

    @RequestMapping("toList")
    public String toList(){

        return "admin/seller";
    }

    @RequestMapping("getInfo")
    @ResponseBody
    public Result getInfo(String name, String nickName){
        List<TbSeller> list = sellerService.getInfo(name,nickName);
        if (list != null){
            return Result.build(ConstantEnum.SUCCESS).setResult(list);
        } else {
            return Result.build(ConstantEnum.ERROR).setResult(list);
        }
    }

    @RequestMapping("toUpdate")
    @ResponseBody
    public Result toUpdate(String sellerId){
        TbSeller tbSeller = sellerService.toUpdate(sellerId);
        if (tbSeller != null){
            return Result.build(ConstantEnum.SUCCESS).setResult(tbSeller);
        } else {
            return Result.build(ConstantEnum.SUCCESS).setResult(tbSeller);
        }
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(TbSeller tbSeller){
        Boolean b = sellerService.update(tbSeller);
        if (b){
            return Result.build(ConstantEnum.SUCCESS);
        } else {
            return Result.build(ConstantEnum.ERROR);
        }
    }
}
